<!--
 * @Descripttion: 
 * @version: 1.0
 * @Author: wuhao
 * @Date: 2021-08-17 13:41:14
 * @LastEditors: wuhao
 * @LastEditTime: 2021-08-17 15:02:39
-->
<template>
  <div class="container">
    <div class="header">
      <p>
        <el-tooltip class="item"
          effect="dark"
          :content="url"
          placement="top-start">
          <span>{{url}}</span>
        </el-tooltip>
      </p>
      <el-button type="primary"
        size="small"
        :data-clipboard-text="url"
        @click="copy()"
        class="link"
        icon="el-icon-copy-document">
      </el-button>
    </div>
    <el-input type="textarea"
      resize="none"
      :rows="6.5"
      placeholder="Please enter content"
      v-model="textarea">
    </el-input>
  </div>
</template>

<script>
import Clipboard from 'clipboard';
export default {
  name: 'Clipboard',
  data() {
    return {
      url: 'https://blog.csdn.net/qq_44722915/article/details/119611359',
      textarea: ''
    }
  },
  methods: {
    copy() {
      let clipboard = new Clipboard('.link')
      clipboard.on('success', e => {
        e
        this.$message({
          message: "复制成功",
          type: "success"
        })
        // 释放内存
        clipboard.destroy()
      })
      clipboard.on('error', e => {
        e
        this.$message.error('该浏览器不支持自动复制')
        // 释放内存
        clipboard.destroy()
      })
    }
  }
}
</script>

<style lang="css" scoped>
.container {
  width: 380px;
  height: 200px;
  border: 1px solid #dcdfe6;
  margin: 0 auto;
  padding: 20px;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 6px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
}
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
p {
  margin-right: 20px;
  height: 30px;
  line-height: 30px;
  width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #909399;
  cursor: pointer;
}
/deep/ .el-button {
  width: 20px;
  height: 20px;
  padding: 0;
  margin: 0;
}
/deep/ .el-textarea {
  margin-top: 20px;
}
</style>


